@extends('Admin.layout.blank')

@section('body')
<section class="Hui-article-box">
<div class="page-container">
	<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页 <span class="c-gray en">&gt;</span> 产品管理 <span class="c-gray en">&gt;</span> 促销列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
		
	<div class="Hui-article">
		<article class="cl pd-20">
			
			<div class="mt-20">
				<table class="table table-border table-bordered table-bg table-hover table-sort"  style="text-align: center;" valign="middle">
					<thead>
						<tr class="text-c">
							<!-- <th width="40"><input name="" type="checkbox" value=""></th> -->
							<th width="20">ID</th>
							<th width="20">商品ID</th>
							<th width="40">分类</th>
							<th width="40">品牌</th>
							<th width="30">图片</th>
							<th width="50">商品名称</th>
							<th width="40">促销开始时间</th>
							<th width="40">促销结束时间</th>
							<th width="40">促销数量</th>
							<th width="40">商品价格</th>
							<th width="40">促销价格</th>
							<th width="20">状态</th>
							<th width="40">操作</th>
							<!-- <th width="100">操作</th> -->
						</tr>
					</thead>
					<tbody>
					@foreach($sale as $v)
						<tr class="text-c va-m">
							<td style="text-align: center; vertical-align:middle">{{ $v->id }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->goods_id }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->goods->types->type_name }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->goods->brands->brand_name }}</td>
							<td style="text-align: center; vertical-align:middle">
								<img width="60px" class="product-thumb" src="http://oydt3ttm3.bkt.clouddn.com/{{ $v->goods->goods_pic }}">
							</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->goods->goods_name }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->start_time }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->end_time }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->promate_num }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->price }}</td>
							<td style="text-align: center; vertical-align:middle">{{ $v->promate_price }}</td>
							<td class="td-status" style="text-align: center; vertical-align:middle">
								@if($v->status == 0)
									<span class="label label-success radius">
										促销中
									</span>	
								@else
									<span class="label label-defaunt radius">
										促销结束
									</span>
								@endif
							</td>
							<td class="td-manage">
								@if($v->status == 0)
								<a style="text-decoration:none" onClick="saleStop(this, {{ $v->id }})" href="javascript:;" title="禁用"><i class="Hui-iconfont">&#xe631;</i></a>
								@else		
								<a style="text-decoration:none" onClick="saleStart(this, {{ $v->id }})" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>
								@endif
								<a style="text-decoration:none" class="ml-5" onClick="saleedit('编辑促销', '{{ route('saleedit', ['id' => $v->id]) }}' ,',','1000','600')" href="javascript:;" title="编辑"><i class="Hui-iconfont">&#xe6df;</i></a>

								<a style="text-decoration:none" class="ml-5" onClick="sale_del(this, {{ $v->id }})" href="javascript:;" title="删除"><i class="Hui-iconfont">&#xe6e2;</i></a>
							</td>
						</tr>
					@endforeach			

					</tbody>
					
				</table>
				
			</div>
		</article>
	</div>
</div>
</section>
@endsection

@section('footer-js')

<!--请在下方写此页面业务相关的脚本--> 
<script type="text/javascript" src="{{ asset('AdminPublic/lib/My97DatePicker/4.8/WdatePicker.js') }}"></script>  
<script type="text/javascript" src="{{ asset('AdminPublic/lib/datatables/1.10.0/jquery.dataTables.min.js') }}"></script> 
<script type="text/javascript" src="{{ asset('AdminPublic/lib/laypage/1.2/laypage.js') }}"></script>
<script type="text/javascript">
$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"aoColumnDefs": [
	  // {"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":false,"aTargets":[0,6]}// 制定列不参与排序
	]
});

// layer.confirm('您是如何看待前端开发？', {
//   btn: ['重要','奇葩'] //按钮
// }, function(){
//   layer.msg('的确很重要', {icon: 1});
// }, function(){
//   layer.msg('也可以这样', {
//     time: 20000, //20s后自动关闭
//     btn: ['明白了', '知道了']
//   });
// });



/*编辑*/
function saleedit(title,url,id,w,h){
	layer_show(title,url,w,h);
}


/*设置促销启用*/
function saleStart(obj,id){
	layer.confirm('确认启用吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("salestart")}}',
			data: 'id='+id,
			
			success:function (msg) {

				//启用失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}	

				//启用成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});

					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="saleStop(this, {{ $v->id }})" href="javascript:;" title="禁用"><i class="Hui-iconfont">&#xe631;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">促销中</span>');
					$(obj).remove();
					// location.reload();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}




/*设置促销禁用*/
function saleStop(obj,id){
	layer.confirm('确认禁用吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("salestop")}}',
			data: 'id='+id,
			
			success:function (msg) {

				//禁用失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}	

				//禁用成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});

					$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="saleStart(this, {{ $v->id }})" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>');
					$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">促销结束</span>');
					$(obj).remove();
					// location.reload();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}


/*删除*/
function sale_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type:'get',
			url:'{{route("saledel")}}',
			data: 'id='+id,
			
			success:function (msg) {

				//删除失败
				if (msg.status == 404) {
					layer.msg(msg.msg, {icon:1,time:1000});
					return false;
				}	

				//删除成功
				if (msg.status == 200) {
					layer.msg(msg.msg, {icon:1,time:1000});
					$(obj).parents("tr").remove();
					return false;
				}
			},
			// error:function (e,a,b) {
			// 	errorObj = JSON.parse(e.responseText);
			// 	console.log(errorObj);
			// },
			dataType:'json'
		});
		// $(obj).parents("tr").remove();
		// layer.msg('已删除!',{icon:1,time:1000});
	});
}



</script>
<!--/请在上方写此页面业务相关的脚本-->

@endsection